﻿using UnityEngine;
using System.Collections;

public class PowerUpSpawner : MonoBehaviour
{

    public GameObject[] powerUp;
    private float Timer;
    public float delayTime;

    void Awake()
    {
        
        Timer = Time.time + delayTime;
    }

    void Update()
    {
        GameObject obj = powerUp[Random.Range(0, powerUp.Length)];
        if (Timer < Time.time)
        {
            //float pos = Random.Range(0, Screen.width); 
            int range = Random.Range(1, 101);
            if (true) //range <= 60)
            {
                MeshFilter viewedModelFilter = (MeshFilter) obj.GetComponent("MeshFilter");
                Vector3 powerUpSize = viewedModelFilter.sharedMesh.bounds.size * obj.transform.localScale.x;
                float minX = WithinBounds.Bounds.minX + 1 * (powerUpSize.x);
                float maxX = WithinBounds.Bounds.maxX - 2 * (powerUpSize.x);
                Instantiate(obj, new Vector3(Random.Range(minX, maxX), obj.transform.position.y, 0), Quaternion.Euler(90f, 270f, 90f));
            }
                Timer = Time.time + delayTime;
        }
    }
}
